package array;

public class xuanArray {
    public void rotate1(int[] array,int k){
        int[] temp=new int[array.length];
        for (int i = 0; i < array.length; i++) {
            temp[(i+k)%array.length]=array[i];
        }
        for (int j:temp) {
            System.out.println(j);
        }
    }

    public void rotate2(int[] array,int k){
        k=k%array.length;


        reverse(array,0,array.length-1);
        reverse(array,0,k-1);
        reverse(array,k, array.length-1);
        for (int j:array) {
            System.out.println(j);
        }
    }
    public int[] reverse(int[] array,int start,int end){
        int temp;
        while(start<=end){
            temp=array[start];
            array[start]=array[end];
            array[end]=temp;
            start++;
            end--;
        }
        return array;
    }

    public static void main(String[] args) {
        int[] array={1,2,3,4,5,6,7};
        xuanArray xuanArray = new xuanArray();
        xuanArray.rotate2(array,3);
    }
}
